'use client';

import EditableTable, { IRefData } from '@/pao/web/dataEdit/dateEditEditableTable';
import { SchoolClass } from '@/data/prisma';
import { ProColumnType } from '@ant-design/pro-components';

import { addRow, deleteRow, editRow, query } from './service';
import { query as queryGrade } from '@/data/modules/grade/service';
const columns: ProColumnType<SchoolClass>[] = [
    {
        title: '编号',
        dataIndex: 'code',
        fixed: 'left',
        sorter: true,
        width: '80px',
    },
    {
        title: '名称',
        dataIndex: 'name',
        sorter: true,
        fixed: 'left',
        width: '150px',
    },    
    {
        title: '年级',
        dataIndex: 'gradeId',
        sorter: true,
        valueType: 'select',
        width: '200px',
        request: async (row) => {
            const grades = await queryGrade({id: row.gradeId }, {});
            return grades.rows.map(grade => ({
                label: `${grade.code} - ${grade.name}`,
                value: grade.id,
            }));
        }
    },
    {
        title: '备注',
        dataIndex: 'comments',
        sorter: true,
        width:300,
    },
];

const config = {
    headerTitle: '班级',
    tooltip: '修改班级信息',
}

export default function SchoolClassControl({refData}: IRefData<SchoolClass>) {
    return <EditableTable<SchoolClass> columns={columns} rowKey="id" config={config} deleteRow={deleteRow} query={query} editRow={editRow} addRow={addRow} refData={refData}/>
}